/*
 * FileName: AkkaClient.java
 * Author:   zzw
 * Date:     2019年01月23日
 * Description:
 */
package com.zzw.rpc.akka;

import akka.actor.*;
import com.typesafe.config.ConfigFactory;

/**
 * 〈〉<br>
 * 〈〉
 *
 * @author zzw
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本]（可选）
 */
public class AkkaClient extends UntypedActor {

    private ActorRef remoteServer = null;

    public AkkaClient(ActorRef inRemoteServer) {
        remoteServer = inRemoteServer;
    }

    @Override
    public void onReceive(Object message) throws Exception {
        remoteServer.tell(message, getSelf());
    }

    public static void main(String[] args) throws InterruptedException {
        /*根据配置,找到System*/
        ActorSystem system = ActorSystem.create("Client", ConfigFactory.load("client").getConfig("flink"));

        String url = "akka.tcp://WCMapReduceApp@127.0.0.1:2552/user/WCMapReduceActor";

        String url2 = "akka.tcp://flink@188.188.22.165:6123/user/resourcemanager";

        /*实例化远程Actor*/
        final ActorRef remoteActor = system.actorFor(url2);

        /*实例化Client的Actor管道*/
        final ActorRef clientActor = system.actorOf(Props.create(AkkaClient.class,remoteActor));

        clientActor.tell("hello",null);

       /*ActorSelection destination = system.actorSelection(url2);
        final String path = "akka.tcp://flink@188.188.22.168:6123/user/resourcemanager";
        final ActorSelection destination = system.actorSelection(path);
        final ActorRef clientActor2 = system.actorOf(Props.create(AkkaClient.class,destination));
        clientActor2.tell("hello-1", clientActor2);
        clientActor2.tell("hello-2", clientActor2);
        clientActor2.tell("hello-3", clientActor2);*/
    }
}
